<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE HTML>
<html lang="en-US">
<head>
	<meta charset="UTF-8">
	<title>凯盛项目管理系统</title>
    <link rel="stylesheet" href="css/bootstrap.css" type="text/css" />
    <link rel = "Shortcut Icon" href="http://www.kaishengit.com/favicon.ico" />
	<script type="text/javascript" src="js/jquery.js"></script>
</head>
<body>
    <div class="container">
		<div class="navbar">
			<div class="navbar-inner">
				<div class="container">
					<a href="main" class="brand">凯盛项目管理系统</a>
					<ul class="nav pull-right">
						<li class="active">
							<a>${sessionScope.user.name }</a>
						</li>
						<li>
							<a href="user">个人资料</a>
						</li>
						<li class="divider-vertical"></li>
						<li>
							<a href="loginout">安全退出</a>
						</li>
					</ul>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="span3">
				<div class="wall">
					<ul class="nav nav-list">
						<li class="nav-header">${project.name }</li>
						<li class="divider"></li>
						<li>
							<a href="project?id=${project.id }">
								<i class=" icon-home"></i>最新动态
							</a>
						</li>
						<li class="active">
							<a href="goal">
								<i class="icon-white icon-flag"></i>目标
							</a>
						</li>
						<li>
							<a href="document">
								<i class="icon-folder-open"></i>资料库
							</a>
						</li>
						<li>
							<a href="folder">
								<i class="icon-file"></i>文件共享
							</a>
						</li>
						<li>
							<a href="contact">
								<i class="icon-user"></i>联系人
							</a>
						</li>
						<li>
							<a href="idea">
								<i class="icon-fire"></i>想法
							</a>
						</li>
						<li>
							<a href="project?m=edit">
								<i class="icon-cog"></i>项目设置
							</a>
						</li>
					</ul>
				</div>
			</div>
            <div class="span9">
                <form class="form-horizontal" id = "myform" method="post" action="task?m=edit&id=${task.id }">
                    <fieldset>
                        <legend>编辑任务</legend>
                        <div class="control-group" id ="namediv">
                            <label class="control-label" for="task_name">任务名称</label>
                            <div class="controls">
                                <input type="text" class="input-xlarge" id="task_name" name="task_name" value="${task.name }">
                                <p class="help-block">请输入任务名称</p>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="start_time">开始时间</label>
                            <div class="controls">
                                <input type="text" class="input-xlarge" id="start_time" name="start_time">
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="end_time">结束时间</label>
                            <div class="controls">
                                <input type="text" class="input-xlarge" id="end_time" name="end_time">
                            </div>
                        </div>
                        <div class="control-group" id ="detaildiv">
                            <label class="control-label" for="task_details">任务描述</label>
                            <div class="controls">
                                <textarea name="task_details" id="task_details" rows="8" class="input-xlarge">${task.detail }</textarea>
                                <p class="help-block">请输入任务的详细描述</p>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="task_state">状态</label>
                            <div class="controls">
                                <select name="task_state" id="task_state">
                                    <option value="新任务">新任务</option>
                                    <option value="进行中">进行中</option>
                                    <option value="已完成">已完成</option>
                                </select>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="task_jibie">级别</label>
                            <div class="controls">
                                <select name="task_jibie" id="task_jibie">
                                    <option value="重要紧急">重要紧急</option>
                                    <option value="重要不紧急">重要不紧急</option>
                                    <option value="紧急不重要">紧急不重要</option>
                                    <option value="不紧急不重要">不紧急不重要</option>
                                </select>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="task_owner">负责人</label>
                            <div class="controls">
                                <select name="task_owner" id="task_owner">
                                	<c:forEach var="user" items="${users }">
                                		<c:choose>
                                			<c:when test="${task.userId eq user.id }">
                                				<option value="${user.id }" selected="selected">${user.name }</option>
                                			</c:when>
                                			<c:otherwise>
                                				<option value="${user.id }">${user.name }</option>
                                			</c:otherwise>
                                		</c:choose>
                                	</c:forEach>
                                </select>
                            </div>
                        </div>
                        <div class="control-group" id="progress">
							<label class="control-label" for="task_progress">任务进度</label>
							<div class="controls">
								<div class="input-append">
									<input id="task_progress" name="task_progress" class="span1" type="text" value="${task.progress }" style="text-align:right"><span class="add-on">%</span>
								</div>
								<span class="help-inline">请输入任务进度，1-100之间的整数</span>
							</div>
						</div>
                        <div class="form-actions">
                            <button class="btn btn-primary" id ="btn" type="button">编辑</button>
                            <a href="task?id=${goal.id }" class="btn">返回</a>
                        </div>
                    </fieldset>
                </form>
            </div>
        </div>
    </div>
          <script type="text/javascript">
    	  $(document).ready(function() {
    	  
    	  	var reg = /^(\d{1,2}|100)$/;

            $("#task_name").focus(function(){
                $("#namediv").removeClass("error");
            });
            $("#task_name").blur(function() {
                var name = $(this).val();
                if (name.trim() == "") {
                    $("#namediv").addClass("error");
                }
            });
            $("#task_details").focus(function() {            
                $("#detaildiv").removeClass("error");
            });
            $("#task_details").blur(function() {
                var pwd = $(this).val();
                if (pwd == "") {                
                    $("#detaildiv").addClass("error");
                }
            });
            $("#task_progress").blur(function() {
                var p = $(this).val();
                if (!reg.test(p)) {
                    $("#progress").addClass("error");
                };
            });
            $("#task_progress").focus(function() {            
                $("#progress").removeClass("error");
            });
            $("#btn").click(function() {
                var name = $("#task_name").val();
                var detail = $("#task_details").val();
                var progress = $("#task_progress").val();
                if (name.trim() == "") {          
                    $("#namediv").addClass("error");
                }
                if (detail == "") {
                    $("#detaildiv").addClass("error");
                }
                if (!reg.test(progress)) {
                    $("#progress").addClass("error");
                };
                if (name.trim() != "" && detail != "" && reg.test(progress)) {
                    $("#myform").submit();
                }
            });
        });
    
    </script>
    
</body>
</html>